﻿⍝ Multi-threading
⍝ Primitives
1111⌶1 ⍝ Number of threads to use
1111⌶4
1112⌶32768 ⍝ Size at which we go parallel
a1←¯1↓ap←32769⍴123.456
b1←¯1↓bp←32769⍴654.321
⎕cmd 'taskmgr.exe' ''
)copy dfns cmpx
cmpx 'a1+b1' 'ap+bp'
cmpx 'a1÷b1' 'ap÷bp'
cmpx 'a1≤b1' 'ap≤bp'
cmpx 'a1⍟b1' 'ap⍟bp'
cmpx 'a1∨b1' 'ap∨bp'

⍝ Parallel Each operator
⎕USING←',system.dll'
System.Diagnostics.Process.Start ⊂'http://tools.dyalog.com/library/index.htm'
)load c:\temp\parallel
{+/1=⍵∨⍳⍵}¨⍳25
{+/1=⍵∨⍳⍵} P.Each ⍳25
]cputime "{+/1=⍵∨⍳⍵} ¨ ⍳10000"
]cputime "{+/1=⍵∨⍳⍵} P.Each ⍳10000"
⍝ Functions with Side-Effects
⎕FX 'r←Count x' 'RESULTS←RESULTS⍪SLAVEID (+/THROWS=x)' 'r←⍬'
⎕VR 'Count'
THROWS←?10000⍴6 ⍝ Roll 10,000 dice
RESULTS←0 2⍴0
P.Set 'Count THROWS RESULTS'
⍳P.ProcessorCount
(⍳P.ProcessorCount) P.Set 'SLAVEID'
P.Get 'SLAVEID'
⍴'Count' P.Each ⍳6
]disp P.Get 'RESULTS'
⊃⍪/P.Get 'RESULTS'
)clear